import 'package:FlutterStudy/ImageStudy.dart';
import 'package:FlutterStudy/iconStudy.dart';
import 'package:FlutterStudy/listViewStudy.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';


import 'AppBarWithImageStack.dart';
import 'AppBarWithNetworkImage.dart';
import 'ToutiaoDemo.dart';
import 'WrapDemo.dart';
// 主题  MaterialApp

void main() {
  runApp(MainHome());
}


/*在不关闭分析错误的提示的时候要求你要设置全局的方向*/
class SimplePage extends StatelessWidget {
  const SimplePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const Center(
      child: Text(
        '我是一个简单的例子提示',
        textDirection: TextDirection.ltr, // 只给单个Text组件设置了方向
        style: TextStyle(
          fontSize: 30.0,
          color: Colors.blue,
          backgroundColor: Colors.amber,
        ),
      ),
    );
  }
}

/*带有主题的组件
*
*
* */

class MainHome extends StatelessWidget {
  const MainHome({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: '/', // 默认第一次加载的哪个页面
      routes: {
        '/': (context, {arguments}) => ToutiaoDemo(), // 这里是一个 function
        '/second': (context, {arguments}) => SimplePage(), // 这里是一个 function
      },
      /* onGenerateRoute: (settings) {

          if (settings.name == '/second') {
            return MaterialPageRoute(builder: (context) => IconStudy());
          } else {
            return MaterialPageRoute(builder: (context) => ListViewStudy());
          }
        },*/
      title: 'Flutter 学习',
      theme: ThemeData(primarySwatch: Colors.blue),

      /* home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter 学习1'),
          backgroundColor: Colors.brown,
        ),
        body: AppBarWithNetworkImage(),
        bottomNavigationBar: BottomNavigationBar(
          items: const [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
            BottomNavigationBarItem(icon: Icon(Icons.person), label: '个人'),
          ],
          backgroundColor: Colors.redAccent,
          onTap: (index) {
            print(index);
          },
        ),
      ),*/
    );
  }



  Widget buildOverflowingRow() =>
      // #docregion overflowing-row
  Row(
    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
    children: [
      Image.asset('images/pic6.jpg', width: 100, height: 100),
      Image.asset('images/pic2.jpg', width: 100, height: 100),
      Image.asset('images/pic3.jpg', width: 100, height: 100),
      Expanded(child: CircleAvatar(

        backgroundImage: AssetImage('images/pic6.jpg'),
        radius: 50,
        child: Container(
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            border: Border.all(color: Colors.grey, width: 2),
          ),
        ),
      ),)

    ],
  );

  // #enddocregion overflowing-row

  Widget buildExpandedImages() =>
      // #docregion expanded-images
  Row(
    crossAxisAlignment: CrossAxisAlignment.center,
    children: [
      Expanded(child: Image.asset('images/pic6.jpg')),
      Expanded(child: Image.asset('images/pic2.jpg')),
      Expanded(child: Image.asset('images/pic3.jpg')),
      Expanded(child: Image.asset('images/pic3.jpg')),
      Expanded(child: Image.asset('images/pic3.jpg')),
    ],
  );

  // #enddocregion expanded-images

  Widget buildExpandedImagesWithFlex() =>
      // #docregion expanded-images-with-flex
  Row(
    crossAxisAlignment: CrossAxisAlignment.center,
    children: [
      Expanded(child: Image.asset('images/pic6.jpg')),
      Expanded(flex: 2, child: Image.asset('images/pic2.jpg')),
      Expanded(child: Image.asset('images/pic3.jpg')),
    ],
  );

  // -----------------------------------------------------row and column-----------

  /*
  Container
   1. 增加 padding、margins、borders

   2.改变背景色或者图片

   3.只包含一个子 widget，但是这个子 widget 可以是 Row、Column 或者是 widget 树的根 widget
  *
  * */

  Widget _buildImageColumn() {
    return Container(
      decoration: const BoxDecoration(color: Colors.black26),
      child: Column(children: [_buildImageRow(1), _buildImageRow(3)]),
    );
  }

  // #enddocregion column

  // #docregion row
  Widget _buildDecoratedImage(int imageIndex) =>
      Expanded(
        child: Container(
          decoration: BoxDecoration(
            border: Border.all(width: 10, color: Colors.black38),
            borderRadius: const BorderRadius.all(Radius.circular(8)),
          ),
          margin: const EdgeInsets.all(4),
          child: Image.asset('images/pic$imageIndex.jpg'),
        ),
      );

  Widget _buildImageRow(int imageIndex) =>
      Row(
        children: [
          _buildDecoratedImage(imageIndex),
          _buildDecoratedImage(imageIndex + 1),
        ],
      );

  static const big = TextStyle(fontSize: 28.0);

  Widget _bulidTest1() =>
      Row(
          children: [
            Flexible(
              child: Container(
                color: Colors.red,
                child: Text('短文本'),
              ),
            ),
            Flexible(
              child: Container(
                color: Colors.green,
                child: Text(
                    '这是很长很长的文本内容这是很长很长的文本内容这是很长很长的文本内容这是很长很长的文本内容这是很长很长的文本内容这是很长很长的文本内容'),
              ),
            ),

          ]


      );
// 加载图片 Image.network (fit)
}
